{% extends 'blank.html.twig' %}
{% block body %}
    <style type="text/css" rel="stylesheet">
        /*这是分页页码的style*/
        #pagecode{width:800px;line-height:30px;text-align:center;}
        .code_block{display:inline-block;width:30px;height:30px;background:rgba(220,220,100,0.5);margin-left:20px;border:1px solid rgba(0,0,0,0.2);}
        #code_form{display:inline-block;width:120px;}
        .code_button{width:32px;height:32px;}
        .code_button:hover{cursor:pointer;}

    </style>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        系统管理
        <span class="c-gray en">&gt;</span>
        数据字典
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="page-container">
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="80">序号</th>
                    <th width="105">名称</th>
                    <th width="105">类名</th>
                    <th width="105">详细</th>
                </tr>
                </thead>
                <tbody>
                {% for item in arrdic %}
                <tr class="text-c">
                    <td>{{ loop.index }}</td>
                    <td>{{ item.table_name }}</td>
                    <td class="comment" title="点击修改描述">{{ item.comment }}</td>
                    <td><a href="javascript:void(0)" onclick="layer_show('{{ item.table_name }}','{{ path('dic_field',{'table_name':item.table_name}) }}',800,500)">详细</a></td>
                </tr>
                {%  endfor %}
                </tbody>
            </table>
        </div>
    </div>
    {% if list_len>per %}
        <div id="pagecode">
            {#计算最大页码#}
            {% if list_len%per == 0 %}
                {% if list_len!=0 %}
                    {% set maxpage = list_len//per %}
                {% else %}
                    {% set maxpage = 1 %}
                {% endif %}
            {% else %}
                {% set maxpage = list_len//per + 1 %}
            {% endif %}
            {#根据当前页生成页码链接#}
            {% if maxpage>=5 %}
                {% if page <=3 %}
                    {% for i in 1..5 %}
                        <a class="code_block" href="/AbsSR/web/app_dev.php/dic_bundle/dic_list?page={{ i }}">{{ i }}</a>
                    {% endfor %}
                {% elseif page >= maxpage - 2 %}
                    {% for i in 1..5 %}
                        <a class="code_block" href="/AbsSR/web/app_dev.php/dic_bundle/dic_list?page={{ maxpage -5 + i }}">{{ maxpage -5 + i }}</a>
                    {% endfor %}
                {% else %}
                    {% for i in 1..5 %}
                        <a class="code_block" href="/AbsSR/web/app_dev.php/dic_bundle/dic_list?page={{ page -3 + i }}">{{ page -3 + i }}</a>
                    {% endfor %}
                {% endif %}
            {% else %}
                {% for i in 1..maxpage %}
                    <a class="code_block" href="/AbsSR/web/app_dev.php/dic_bundle/dic_list?page={{ i }}">{{ i }}</a>
                {% endfor %}
            {% endif %}
            <form id="code_form" action="/AbsSR/web/app_dev.php/dic_bundle/dic_list" method="get">
                <input class="code_block code_button" type="submit"  value="转到"/>
                <input class="code_block" placeholder="页码" value="" name="page" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" />
            </form>
        </div>
    {% endif %}
    <script type="text/javascript">
        //双击修改注释
        (function(){
            var comment_arr = document.getElementsByClassName('comment');
            for(var i=0;i<comment_arr.length;i++){
                comment_arr[i].ondblclick=function(){
                    this.innerHTML = '<input onblur="setComment(this)" placeholder="'+this.innerHTML+'" value="'+this.innerHTML+'" />';
                    this.ondblclick = null;
                }
            }
        })();

        //ajax修改注释
        function setComment(input){
            var xmlHttp;
            var tableName = input.parentNode.parentNode.children[1].innerHTML;
            var comment = input.value;
            //将查询条件添加到path中
            var url = "{{ path('dic_comment') }}";
            url+='?target='+tableName+'&comment='+comment;
            if(window.XMLHttpRequest){
                xmlHttp = new XMLHttpRequest();
            }else{
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlHttp.onreadystatechange = function(){
                if(xmlHttp.readyState == 4 && xmlHttp.status==200 ){
                    input.parentNode.ondblclick=function(){
                        this.innerHTML = '<input onblur="setComment(this)" placeholder="'+this.innerHTML+'" value="'+this.innerHTML+'" />';
                        this.ondblclick = null;
                    };
                    input.parentNode.innerHTML = xmlHttp.responseText;
                }else if(xmlHttp.readyState == 4 && xmlHttp.status==500) {
                    input.parentNode.ondblclick = function () {
                        this.innerHTML = '<input onblur="setComment(this)" placeholder="' + this.innerHTML + '" value="' + this.innerHTML + '" />';
                        this.ondblclick = null;
                        input.parentNode.innerHTML = input.placeholder;
                    };
                }
            };
            xmlHttp.open("GET",url,true);
            xmlHttp.send();
        }


    </script>
{% endblock %}